/*
* Copyright 2015 2dfire.com All right reserved. This software is the
* confidential and proprietary information of 2dfire.com ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with 2dfire.com.
*/
package com.twodfire.merchant.poi;

import java.beans.*;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * @author guipi
 * @description
 * @date 2017/7/8
 * ----------重大变更记录------------
 */
public class ReadConfig extends AbstractConfig {

    private Class objectClazz;
    private Class arrayClazz;
    private Map<String,Method> objectMethodMap = new HashMap<>();
    private Map<String,Method> arrayMethodMap = new HashMap<>();

    public Class getObjectClazz() {
        return objectClazz;
    }

    public void setObjectClazz(Class objectClazz) throws IntrospectionException {
        this.objectClazz = objectClazz;
        if(objectKeys == null){
            objectKeys = new HashSet<>();
        }
        generatorKeyAndMethod(objectClazz,objectKeys,objectMethodMap);
    }

    public Class getArrayClazz() {
        return arrayClazz;
    }

    public void setArrayClazz(Class arrayClazz) throws IntrospectionException {
        this.arrayClazz = arrayClazz;
        if(arrayKeys == null){
            arrayKeys = new HashSet<>();
        }
        generatorKeyAndMethod(arrayClazz,arrayKeys,arrayMethodMap);
    }

    private void generatorKeyAndMethod(Class clazz, Collection<String> keys, Map<String, Method> map) throws IntrospectionException {
        if(keys.isEmpty()){
            if(!clazz.isAssignableFrom(Map.class)){
                generatorKeyAndMethod(clazz, keys,map,"set");
            }
        }else if(map.isEmpty()){
            if(!clazz.isAssignableFrom(Map.class)){
                generatorMethod(clazz, keys, map,"set");
            }
        }
    }

    public Map<String, Method> getObjectMethodMap() {
        return objectMethodMap;
    }

    public Map<String, Method> getArrayMethodMap() {
        return arrayMethodMap;
    }

}
